package pl.edu.agh.anomalyids.lerad.aspect.implementation;

import pl.edu.agh.anomalyids.lerad.aspect.enums.AspectType;
import pl.edu.agh.anomalyids.lerad.aspect.enums.Match;
import pl.edu.agh.anomalyids.network.Packet;
import pl.edu.agh.anomalyids.network.Packet.Protocol;
import pl.edu.agh.anomalyids.network.header.Header;
import pl.edu.agh.anomalyids.network.header.impl.IPv4Header;

public class SrcIpAddressAspect extends IpAddressAspect {

	private static final long serialVersionUID = 8264099268390698957L;

	public SrcIpAddressAspect(String ip) {
		super(ip, AspectType.SRCIP);
	}

	@Override
	public Match packetMatchesAspect(Packet packet) {
		Header header = packet.getProtocols().get(Protocol.IPv4);
		if (header != null) {
			IPv4Header ip = (IPv4Header) header;
			if (validate(ip.getSrcAddress())) {
				return Match.SAME;
			} else {
				return Match.DIFFER;
			}
		} else {
			return Match.UNKNOWN;
		}
	}

}
